package com.blue.controller;

import com.blue.example.Product;
import com.blue.utils.SBTFxDialog;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;

/**
 * Created by Administrator on 2019/8/3.
 */
public class ChangeProjectController implements Initializable {

    public static StringBuffer selectFlags;
    public static ArrayList<String> webList;
    private Product product = new Product();
    @FXML
    private AnchorPane projectAnchorPane;
    @FXML
    private Line projectLine1;
    @FXML
    private Circle projectCircle1;

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        //step process
        projectLine1.setStroke( Color.GREEN );
        projectLine1.setStrokeWidth( 4.0 );
        projectCircle1.setFill( Color.GREEN );
        //product = new Product();
        if (ChangeConfigController.selectFlags != null && !"".equals( ChangeConfigController.selectFlags.toString() )) {
            product.setSelectFlags( ChangeConfigController.selectFlags );
        }
        GridPane gridPane = product.addproductnew();
        AnchorPane.setTopAnchor( gridPane, 10.0 );
        projectAnchorPane.getChildren().addAll( gridPane );


    }

    public void addTomcat(ActionEvent actionEvent) {
        webList = product.webList;
        selectFlags = product.selectFlags;
        System.out.println( "----------" + selectFlags.toString() );
        System.out.println( "selected projects---------->" + webList.toString() );
        if ("".equals( product.selectFlags.toString() )) {
            SBTFxDialog.showMessageDialog( (Stage) projectAnchorPane.getScene().getWindow(), "请选择需要自定义安装的项目，否则请默认安装！", "web项目安装配置提示" );
        }
        if (!"".equals( product.selectFlags.toString() )) {
            //创建主界面舞台
            Stage mainStage = (Stage) projectAnchorPane.getScene().getWindow();
            //读入布局
            FXMLLoader fxmlLoader = new FXMLLoader( getClass().getResource( "/fxml/tomcat.fxml" ) );
            BorderPane root = null;
            try {
                root = fxmlLoader.load();
            } catch (IOException e) {
                e.printStackTrace();
            }
            Scene scene = projectAnchorPane.getScene();
            scene.setRoot( root );
            scene.getStylesheets().add( "/css/style.css" );
            mainStage.setTitle( "Product Installation System of BLUE" );
            mainStage.setMaximized( true );
            mainStage.setScene( scene );
            mainStage.getIcons().add( new Image( "/img/logo.png" ) );
            //mainStage.show();
            //将这个管理员信息传给主控制器
                /*Admin admin = adminService.getAdminByAccount( account );
                Installrocess controller = fxmlLoader.getController();
                controller.setAdmin( admin );*/
            /*Stage loginStage = (Stage) projectAnchorPane.getScene().getWindow();
            loginStage.close();*/
        }
    }

}
